import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);

let routers = [
    {
        path: '/',
        name: 'Home',
        component: () => import('@/views/Home'),
        meta: {
            title: '数据授权',
        },
    },
];
[
    'apply',
    'authorization',
    'detail',
    'signForCorp', // 单位注册
    'signForScene', // 场景签署
    'signForExpert', // 专家签署
    'signForData', // 大数据签署
    'signForSceneAuth', // 场景签署
    'test',
].forEach((name) => {
    let _name = name.charAt(0).toUpperCase() + name.slice(1);
    let meta = {
        title: '数据授权',
    };
    switch (name) {
        case 'signForCorp':
            meta.title = '签署《入驻承诺书》';
            break;
        case 'signForExpert':
            meta.title = '签署《专家评审意见》';
            break;
    }
    routers.push({
        path: `/${name}`,
        name: _name,
        component: (resolve) => require([`@/views/${_name}`], resolve),
        meta,
    });
});

const router = new Router({
    mode: 'hash',
    scrollBehavior: () => ({ y: 0 }),
    routes: routers,
});

// 导航前置守卫，可以在确定导航到目标页面时再更改title
router.beforeEach((to, from, next) => {
    window.document.title = to.meta.title;
    next();
});

export default router;
